/**
 * Created by Administrator on 2017/3/17 0017.
 */
Page5={
    Create:function(){
        var page={};
        var whole=new PIXI.DisplayObjectContainer();
        var bg=PSP("page6_1");
        var bgMask=new PIXI.Graphics();

        var hitSound=document.getElementById("JaudioHit");
        var hitSound2=document.getElementById("JaudioHit2");
        var hitSound3=document.getElementById("JaudioHit3");

        bgMask.beginFill(0x000000,1);
        bgMask.drawRect(0,0,740,1136);
        bg.mask=bgMask;
        var pink=PSP("page6_2");
        pink.blendMode=PIXI.BLEND_MODES.MULTIPLY;
        whole.addChild(bg);
        whole.addChild(pink);
        var arr=[];
        for(var z=3;z<=10;z++){
            var word=PSP("page6_"+z);
            switch(z){
                case 3:word.x=592;word.y=0;break;
                case 4:word.x=592;word.y=163;break;
                case 5:word.x=592;word.y=317;break;
                case 6:word.x=592;word.y=405;break;
                case 7:word.x=592;word.y=549;break;
                case 8:word.x=592;word.y=753;break;
                case 9:word.x=592;word.y=918;break;
                case 10:word.x=592;word.y=1045;break;
            }
            whole.addChild(word);
            arr.push(word);
            word.alpha=0;
        }

        var title1=PSP("page6_11");
        var title2=PSP("page6_12");
        var title3=PSP("page6_13");
        var title4=PSP("page6_14");
        var title5=PSP("page6_15");
        var title6=PSP("page6_16");
        var title7=PSP("page6_17");
        var title8=PSP("page6_18");
        title8.anchor.set(0.5);
        var frame=PSP("page6_19");
        var logo=PSP("page6_20");





        pink.x=0;pink.y=663;
        title1.x=166;title1.y=222;
        title2.x=278;title2.y=665;
        title3.x=199+title3.width/2;title3.y=378;
        title4.x=287;title4.y=220;
        title5.x=208;title5.y=576;
        title6.x=387;title6.y=225;
        title7.x=183;title7.y=583;
        title8.x=255+title8.width/2;title8.y=409+title8.height/2;
        frame.x=33;frame.y=26;
        logo.x=56;logo.y=45;




        whole.addChild(title8);
        whole.addChild(title1);
        whole.addChild(title2);
        whole.addChild(title3);
        whole.addChild(title4);
        whole.addChild(title5);
        whole.addChild(title6);
        whole.addChild(title7);
        whole.addChild(frame);
        whole.addChild(logo);
        whole.addChild(bgMask);


        title1.alpha=0;
        title2.alpha=0;
        title3.alpha=0;
        title4.alpha=0;
        title5.alpha=0;
        title6.alpha=0;
        title7.alpha=0;
        title8.alpha=0;

        frame.alpha=0;
        logo.alpha=0;

        // bg.alpha=0;
        pink.alpha=0;

        bgMask.y=-1136;




        var num=0;
        var times=0;
        function wordAppearance(){

            for (var z = 0; z < arr.length; z++) {
                var w = arr[z].width;
                var h = arr[z].height;
                var x = arr[z].x;
                var y = arr[z].y;
                arr[z].anchor.set(0.5);
                arr[z].scale.set(0.1);

                arr[z].x = 370;
                arr[z].y =1136/2-100+20*z;
                num+=0.01;
                var delayTime =1+0.3*z-z*num;
                TweenMax.to(arr[z], 1, {delay: delayTime,
                    alpha: 1, x: 200+Math.random()*30, y: 261 + 50 * z, rotation: Math.PI / 180 * -38, ease: Cubic.easeInOut});
                TweenMax.to(arr[z].scale, 1, {delay: delayTime, x: 1.6, y: 1.6});

                TweenMax.to(arr[z], 0.4, {delay:  delayTime+1,
                    alpha: 1, x: x+w / 2, y: y + h / 2, rotation: 0, ease: Cubic.easeIn});
                TweenMax.to(arr[z].scale, 0.4, {delay: delayTime+1, x: 1, y: 1});
                Shake(delayTime+1.4);

                // console.log(delayTime+1.4);
            }
        }
        var bala=0;
        function Shake(time) {
            setTimeout(function(){
                bala++;
                if(bala%3==0){
                    hitSound2.currentTime=0;
                    hitSound2.play();
                    console.log("0")
                }
                else if(bala%3==1){
                    hitSound.currentTime=0;
                    hitSound.play();
                    console.log("1")
                }
                else{
                    hitSound3.currentTime=0;
                    hitSound3.play();
                    console.log("2")
                }

            },time*1000-150)

            times++;


            TweenMax.to(whole, 0.02, {delay: time, x: 10, y: 4});
            TweenMax.to(whole, 0.02, {delay: time + 0.02, x: -8, y: -8});
            TweenMax.to(whole, 0.02, {delay: time + 0.04, x: 6, y: 8});
            TweenMax.to(whole, 0.02, {delay: time + 0.06, x: -4, y: 5});
            TweenMax.to(whole, 0.02, {delay: time + 0.08, x: 0, y: 0});
            if (times <=8) {
                TweenMax.to(bgMask, 0.02, {delay: time, y: -1136 + 1136 / 8 * times})
                // TweenMax.to(bg,0.02,{delay:time,alpha:1/8*times})
            }
        }





        page.start=function(){

            wordAppearance();
            title8.rotation=Math.PI/180*30;


            TweenMax.to(title8.scale,1,{delay:4,x:3,y:3,ease:Cubic.easeInOut});
            TweenMax.to(title8,1,{delay:4,alpha:1,rotation:Math.PI/180*-30,ease:Cubic.easeInOut});
            TweenMax.to(title8.scale,0.5,{delay:5,x:1,y:1,ease:Cubic.easeIn});
            TweenMax.to(title8,0.5,{delay:5,rotation:0,ease:Cubic.easeIn});
            Shake(5.5);

            pink.y=1136;
            TweenMax.to(pink,0.5,{delay:5.5,alpha:1,x:0,y:663,ease:Cubic.easeOut});
            TweenMax.to(title4,0.02,{delay:5.5,alpha:1,ease:Cubic.easeOut});
            TweenMax.to(title5,0.02,{delay:5.5,alpha:1,ease:Cubic.easeOut});
            TweenMax.to(title6,0.02,{delay:5.5,alpha:1,ease:Cubic.easeOut});
            TweenMax.to(title7,0.02,{delay:5.5,alpha:1,ease:Cubic.easeOut});

            TweenMax.to(title4,1,{delay:8.2,y:title4.y+40,alpha:0,ease:Cubic.easeOut});
            TweenMax.to(title5,1,{delay:8.2,y:title5.y-40,alpha:0,ease:Cubic.easeOut});
            TweenMax.to(title6,1,{delay:8,x:title6.x+50,alpha:0,ease:Cubic.easeOut});
            TweenMax.to(title7,1,{delay:8,x:title7.x-50,alpha:0,ease:Cubic.easeOut});


            TweenMax.to(title8.scale,0.5,{delay:8.4,x:0,ease:Cubic.easeOut});
            title1.y-=40;title2.y+=40;
            TweenMax.to(title1,1,{delay:8.9,y:title1.y+40,alpha:1,ease:Cubic.easeOut});
            TweenMax.to(title2,1,{delay:8.9,y:title2.y-40,alpha:1,ease:Cubic.easeOut});
            title3.scale.x=0;
            title3.anchor.set(0.5,0);
            TweenMax.to(title3,1,{delay:8.9,alpha:1,ease:Cubic.easeOut});
            TweenMax.to(title3.scale,1,{delay:8.9,x:1,ease:Cubic.easeOut});


            frame.x-=40;logo.x+=30;
            TweenMax.to(frame,1,{delay:9.2,alpha:1,x:frame.x+40,ease:Cubic.easeOut});
            TweenMax.to(logo,1,{delay:9.5,alpha:1,x:logo.x-30,ease:Cubic.easeOut});


            // TweenMax.to(pink,1,{delay:0.5,alpha:1,ease:Back.easeOut});
            // TweenMax.to(pink.scale,2,{delay:0.5,x:6,ease:Back.easeOut});
        }

        page.In=function(){

        }
        page.Out=function(){

        }
        page.ReturnWhole=function(){
            return whole;
        }
        return page;
    }
}
